package com.nengchuan.eic.nceconomy.controller;

import com.nengchuan.eic.nceconomy.entity.dto.OssUploadDTO;
import com.nengchuan.eic.nceconomy.entity.dto.ProjectDTO;
import com.nengchuan.eic.nceconomy.entity.vo.OssStsconfigResponseVO;
import com.nengchuan.eic.nceconomy.entity.vo.OssUploadAddFileResponseVO;
import com.nengchuan.eic.nceconomy.entity.vo.ProjectVO;
import com.nengchuan.eic.nceconomy.service.OssService;
import com.nengchuan.model.model.WrappedResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述:
 *
 * @Author: liurui
 * @Date: 2020/6/3 0003 下午 3:25
 */
@RestController
@RequestMapping("/file")
@Api(value = "FileController", tags = "文件服务")
public class FileController {
    @Autowired
    private OssService ossService;

    @ApiOperation("获取oss上传必要信息")
    @PostMapping(value = "/upload_info", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponse(code = 200, message = "成功为true,失败为false", response = WrappedResult.class)
    public WrappedResult<OssStsconfigResponseVO> getList() {
        WrappedResult<OssStsconfigResponseVO> nceconomy = ossService.getOssInfo("eic-nceconomy-service", "nceconomy");
        return WrappedResult.success(nceconomy==null?null:nceconomy.getData());
    }


    @ApiOperation("oss上传")
    @PostMapping(value = "/oss_upload", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponse(code = 200, message = "成功为true,失败为false", response = WrappedResult.class)
    public WrappedResult<Long> ossUpload(@RequestBody OssUploadDTO dto) {
        WrappedResult<OssUploadAddFileResponseVO> ossUploadAddFileResponseVOWrappedResult = ossService.ossUpload(dto.getFileName(), dto.getServiceName(), dto.getFileSuffixName(), dto.getPathName(), dto.getBucket());
        return WrappedResult.success(ossUploadAddFileResponseVOWrappedResult==null?null:ossUploadAddFileResponseVOWrappedResult.getData().getId());
    }


}
